import time
from selenium.webdriver.common.by import By
from Base.base_action import BaseAction


class BeautyMakeupRank(BaseAction):
    beauty_makeup_rank = (By.XPATH, "//*[contains(@text, '美妆榜')]")  # 美妆榜按钮
    product_type = (By.CLASS_NAME, "android.widget.LinearLayout")  # 产品类型
    search_btn = (By.ID, "org.c2h4.afei.beauty:id/tool_search")  # 右上角搜索按钮
    swipe_right = (500, 1000, 200, 1000, 500)
    swipe_left = (500, 1000, 800, 1000, 500)

    def click_makeup_button(self):
        self.click_element(self.beauty_makeup_rank)
        time.sleep(1)

    # 测试美妆榜的左右滑动功能
    def swipe_test(self):
        lenth = 13
        for _ in range(lenth):
            self.swipe(*self.swipe_right)
        for _ in range(lenth):
            self.swipe(*self.swipe_left)

    # 测试在美妆榜各个页面点击搜索按钮
    def search_test(self):
        lenth = 13
        for _ in range(lenth):
            self.swipe(*self.swipe_right)
            self.click_element(self.search_btn)
            time.sleep(1)
            for i in range(2):
                self.key_event(4)

    def makeup_rank_test(self):
        self.click_makeup_button()
        self.swipe_test()
        self.search_test()
